package com.wise.site.model;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> {
	
	private Context mContext;
	private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();

	public CustomItemizedOverlay(Drawable drawable) {
		super(boundCenter(drawable));
		// TODO Auto-generated constructor stub
	}
	
	public CustomItemizedOverlay(Drawable drawable, Context context){
		super(drawable);
		this.mContext = context;
	}

	@Override
	protected OverlayItem createItem(int i) {
		// TODO Auto-generated method stub
		return mapOverlays.get(i);
	}

	@Override
	public int size() {
		// TODO Auto-generated method stub
		return mapOverlays.size();
	}
	
	public void addOverlay(OverlayItem overlay) {
		mapOverlays.add(overlay);
		this.populate();
	}
	
	@Override
	protected boolean onTap(int index) {
		// TODO Auto-generated method stub
		OverlayItem item = mapOverlays.get(index);
		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		dialog.setTitle(item.getTitle());
		dialog.setMessage(item.getSnippet());
		dialog.show();
		return true;
	}

}
